package com.liuyu.common.framework.security;

import com.liuyu.common.framework.common.constant.SelfPowerConstants;
import com.liuyu.common.framework.security.filter.SecurityFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName SecurityConf
 * @Description: TODO
 * @Author: liuyu
 * @Date: Created in 2020/12/25 20:51
 * @Version: 1
 * @Modified By:
 */
@Configuration

public class SecurityConf {
    @Bean
    @SuppressWarnings("all")
    public FilterRegistrationBean sessionFilter() {
        //新建过滤器注册类
        FilterRegistrationBean registration = new FilterRegistrationBean();
        // 添加我们写好的过滤器
        registration.setFilter(new SecurityFilter());
        // 设置过滤器的URL模式
//        registration.setDispatcherTypes({DispatcherType.REQUEST);
        //List<String> urlPatterns = new ArrayList<>();
        //urlPatterns.add("/*");
        //registration.setUrlPatterns(urlPatterns);
        registration.addUrlPatterns(SelfPowerConstants.SECURITY_SELF_PATH + "/*");
        //不过滤的路径，俗称白名单
        registration.addInitParameter("exclusions", "/weixinLoginSuccess,/swagger-ui/,/v2/api-docs,/swagger-resources/**,/webjars/**,/admin/**,/mock/login,/message/test");
        //设置过滤器顺序
        registration.setOrder(1);
        return registration;
    }

}
